*Computes outliers in domestic output price

gen flag_p_dom = 0

gen cpc3_num = cpc3
gen double firm_prod = firm * 10000 + cpc3_num
sort firm_prod year
by firm_prod: gen first = year[_n]==year[_n-1]
drop if first ==1 
drop first
tsset firm_prod year

gen str cpc3_str = string(cpc3)
encode cpc3_str, gen(cpc3_list)

*Computes total number of products, then top and bottom 2.5% of prices within each product
bys cpc3_num: gen first = cpc3_num[_n] ~= cpc3_num[_n-1]
egen max_prod = sum(first)
drop first
local max_prod_s = max_prod
sum max_prod
forvalues i = 1(1)`max_prod_s'  {
   capture xtile test = p_fjt_dom if cpc3_list == `i', n(40)
   capture replace flag_p_dom = 1 if test == 1 | test == 40 
   capture drop test
}
drop cpc3_num cpc3_str cpc3_list firm_prod max_prod



